package com.yeeft.ocr.web;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yeeft.ocr.domain.entity.OcrLog;
import com.yeeft.ocr.domain.entity.UserTest;
import com.yeeft.ocr.mapper.OcrLogMapper;
import com.yeeft.ocr.mapper.UserTestMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 功能简要描述
 *
 * @author 赵仲文
 * @Copyright (c) 2016, frontpay.cn
 * @date 2018/5/8 11:31
 */
@Controller
public class TestController {

    @RequestMapping(value = "/health")
    public @ResponseBody
    String test() {
        return "OK";
    }

    @Autowired
    UserTestMapper userTestMapper;
    @Autowired
    OcrLogMapper ocrLogMapper;

    @RequestMapping(value = "/dbHealth")
    public @ResponseBody
    String dbTest() {
        UserTest u = userTestMapper.findUserByPhone("zhaozw");
        if (u != null) {
            return "DB OK";
        }

        return "Failed!";
    }

    @RequestMapping(value = "/pages")
    public @ResponseBody
    PageInfo<OcrLog> getPages(Integer pageNum, Integer pageSize) {
        //PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
        //PageHelper.startPage(Integer.parseInt(request.getParameter("pageNum")), Integer.parseInt(request.getParameter("pageSize")));
        PageHelper.startPage(pageNum, pageSize);
        List<OcrLog> ocrLogs = ocrLogMapper.selectLogs();
        PageInfo result = new PageInfo(ocrLogs);
        return result;
    }
}
